
package com.mflex.WHSmartWhouseAd.activity;

import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;

import com.mflex.WHSmartWhouseAd.R;
import com.mflex.WHSmartWhouseAd.adapter.MaterialOutStockAdapter;
import com.mflex.WHSmartWhouseAd.adapter.WMSOutStockAdapter;
import com.mflex.WHSmartWhouseAd.model.MaterialTaskModel;
import com.mflex.WHSmartWhouseAd.model.WHDelistTaskModel;
import com.mflex.WHSmartWhouseAd.utils.XToastUtils;
import com.xuexiang.xhttp2.XHttp;
import com.xuexiang.xhttp2.callback.SimpleCallBack;
import com.xuexiang.xhttp2.exception.ApiException;
import com.xuexiang.xui.utils.WidgetUtils;
import com.xuexiang.xui.widget.dialog.MiniLoadingDialog;
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog;
import com.xuexiang.xutil.common.StringUtils;
import com.xuexiang.xutil.net.JsonUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class WMSOutStockActivity extends BaseActivity implements AdapterView.OnItemClickListener {

    Spinner SpStorageType;
    ListView txtList;
    MiniLoadingDialog mMiniLoadingDialog;

    String userName;
    List<WHDelistTaskModel> WMSTaskModelList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_wms_outstock);
        mMiniLoadingDialog = WidgetUtils.getMiniLoadingDialog(this, "加载...");

        SpStorageType= findViewById(R.id.StvStorageType);

        List<String> list=new ArrayList<String>();
        list.add("");
        list.add("智能仓");
        list.add("非智能仓");
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,list);
        adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
        SpStorageType.setAdapter(adapter);
        SpStorageType.setSelection(0);
        txtList= findViewById(R.id.lvList);


        Intent intent = getIntent();
        userName = intent.getStringExtra("userName");

        SpStorageType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                if (SpStorageType.getSelectedItem().toString().isEmpty()) {
                    mMiniLoadingDialog.dismiss();
//                    MediaPlayer mp = MediaPlayer.create(WMSOutStockActivity.this, R.raw.error_voice);mp.start();
                    XToastUtils.success("请先选择仓别属性", 1500);
                    return ;
                }
                XHttp.get("api/WHSmartWhousePDA/GetSmartTaskListForDelist")
                        .params("TaskType", SpStorageType.getSelectedItem().toString())
                        .syncRequest(false)
                        .onMainThread(true)
                        .timeOut(120000)
                        .execute(new SimpleCallBack<List<WHDelistTaskModel>>() {
                            @Override
                            public void onSuccess(List<WHDelistTaskModel> response) {
                                mMiniLoadingDialog.dismiss();
                                WMSTaskModelList=response;
                                WMSOutStockAdapter WMSOutStockDetailAdapter = new WMSOutStockAdapter(WMSOutStockActivity.this, WMSTaskModelList);
                                txtList.setAdapter(WMSOutStockDetailAdapter);
                            }
                            @Override
                            public void onError(ApiException e) {
                                mMiniLoadingDialog.dismiss();
                                MediaPlayer mp = MediaPlayer.create(WMSOutStockActivity.this, R.raw.error_voice);mp.start();
                                XToastUtils.error("请选择仓别属性!",1500);
                                return;
                            }
                        });
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });





        txtList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent(WMSOutStockActivity.this, WMSOutStockTaskActivity.class);
                intent.putExtra("TaskNo", WMSTaskModelList.get(i).getTaskNo());
                intent.putExtra("StorageType", SpStorageType.getSelectedItem().toString());
//                intent.putExtra("WHDelistTaskDetails", JsonUtil.toJson(WMSTaskModelList.get(i).getWHDelistTaskDetails()));
                startActivity(intent);
            }
        });

    }

    @Override
    public void onClick(View view) {

    }

    @Override
    public boolean onKey(View view, int i, KeyEvent keyEvent) {
        return false;
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

    }
}



